
package com.kugou.game.sdk.adapter;

import java.util.ArrayList;

import android.view.ViewGroup;

import com.kugou.framework.v4.Fragment;
import com.kugou.framework.v4.FragmentManager;
import com.kugou.framework.v4.FragmentPagerAdapter;

/**
 * 描述:游戏中心viewpager适配器,通过函数setFragments()来设置需要适配的fragment
 * 
 * @author chenys
 * @since 2013-9-27 上午10:01:21
 */
public class AppCenterViewPagerAdapter extends FragmentPagerAdapter {

    private ArrayList<Fragment> mFragments;

    public AppCenterViewPagerAdapter(FragmentManager fm) {
        super(fm);
    }

    public void setFragments(ArrayList<Fragment> fragments) {
        this.mFragments = fragments;
    }

    @Override
    public Fragment getItem(int position) {
        if (mFragments != null && mFragments.size() > 0) {
            return mFragments.get(position);
        } else {
            return null;
        }
    }

    @Override
    public int getCount() {
        if (mFragments != null) {
            return mFragments.size();
        } else {
            return 0;
        }
    }

    /**
     * 重写此方法，不做实现，可防止子fragment被回收
     */
    @Override
    public void destroyItem(ViewGroup container, int position, Object object) {
    }

}
